<?php

namespace relay;

class Client
{

    /**
     * 控制器
     * @param string $action open 打开    close 关闭    status 状态
     * @param string $which 第几组开关(可选01.02)
     * @param string $id 设备id
     * @param int $times 关闭时间(秒),填写0将不自动下线
     * @param int $minute_money 每分钟多少钱
     * @param string $uid uid
     * @return array|mixed
     */
    public function push($action = 'open', $which = '01', $id, $times = 0, $uid, $minute_money)
    {
        $socket = socket_create(AF_INET, SOCK_STREAM, 0);
        if ($socket < 0) return false;
        $result = @socket_connect($socket, '211.149.242.184', 50000);
        if ($result == false) return false;
        $str = json_encode([
            'action' => $action,
            'which' => $which,
            "id" => $id,
            'uid' => $uid,
            'times' => $times,
            'minute_money' => $minute_money,
        ]);
        socket_write($socket, $str, strlen($str));
        $buf = @socket_read($socket, 1024);
        return $buf;
    }
}

